<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$app->get('php/info', function () use ($app) {
    phpinfo();
});

$app->get('/', function () use ($app) {
    return $app->version();
});

$app->get('/brands', 'CarController@brands');

$app->get('/brand/{brand_id}/models', 'CarController@models');

$app->get('/model/{model_id}/objects', 'CarController@modelObjects');

$app->get('/objectInfo/mi_key/{mi_key}', 'CarController@objectInfo');
$app->get('/objectInfo/vin/{vin}', 'CarController@objectInfoFromVin');

// 来源：http://www.cnblogs.com/duanweishi/p/6151721.html
$app->post('users/login', 'UserController@login');
$app->post('users/register', 'UserController@register');
$app->get('users/register', 'UserController@register');
$app->get('users/info', [
    'middleware' => 'authToken',
    'uses' => 'UserController@info'
]);


$app->group([
    'prefix' => 'backend',
    'namespace' => 'Backend',
    'middleware' => 'authToken',
],function() use( $app ){
    $app->get('/brands', 'BrandController@brands');
    $app->get('/brand/{brand_id}', 'BrandController@brand');
    $app->post('/brand/{brand_id}/edit', 'BrandController@brand_edit');


    $app->get('/factories', 'FactoryController@getList');
    $app->get('/factory/{factory_id}', 'FactoryController@single');
    $app->post('/factory/{factory_id}/edit', 'FactoryController@factory_edit');

    $app->get('/models', 'ModelController@getList');
    $app->get('/model/{model_id}', 'ModelController@single');
    $app->post('/model/{model_id}/edit', 'ModelController@edit');

    $app->get('/model_objects', 'ModelObjectController@getList');
    $app->get('/model_object/{model_object_id}', 'ModelObjectController@single');
    $app->post('/model_object/{model_object_id}/edit', 'ModelObjectController@edit');

    $app->get('/oil/all', 'OilController@all');
    $app->get('/oil/list', 'OilController@getList');
    $app->get('/oil/{id}', 'OilController@single');
    $app->post('/oil/{id}/edit', 'OilController@edit');
    $app->post('/oil/delete', 'OilController@delete');

    $app->get('/vin/list', 'VinController@getList');
    $app->get('/vin/{vin}', 'VinController@single');
    $app->post('/vin/{vin}/edit', 'VinController@edit');
    $app->get('/vin/log/list', 'VinLogController@getList');
});

$app->get('/test/preg', function() use($app){

    $string = '上海大众 大众 桑塔纳（桑塔纳2000）三厢 2003款 1.8L 自动 1.8 自动 GSi 时代阳光';
    $string1 = '通用汽车 雪佛兰 Impala [英帕拉]（Impala [英帕拉]）三厢 1996款 5.7L 自动 5.7 自动';
    $string2 = '奥迪汽车 奥迪 A1（A1）两厢 2012款 1.4L 自动 1.4TFSI 双离合 Ego';
    $preg = '/(.*?)\s(.*?)\s(.*厢)\s(\d{4}款)\s([\d.]+L)\s(.*?)\s([\d.\w]+)\s(.*?)(\s.*)?$/';
    preg_match( $preg, $string2, $matches );
    echo $string2;
    echo '<br/>';
    print_r( $matches );
});
$app->get('/test/lopal', [
    'uses' => 'CarController@testLopal'
]);
// 导入对应油品的方法
//$app->get('/insert/data', [
//    'uses' => 'CarController@insertData'
//]);
//$app->get('/update/data', [
//    'uses' => 'CarController@updateData'
//]);
